import Vue from 'vue';
import VueRouter from 'vue-router';

Vue.use(VueRouter);

const originalPush = VueRouter.prototype.push;
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err);
}

export default new VueRouter({
  routes: [
    {
      path: '/',  // 程序启动默认路由
      component: () => import('@/components/common/Whole.vue'),
      meta: { title: '整体页面布局' },
      redirect: '/Home',  // 重定向到首页
      children: [
        {
          path: '/Home',
          component: () => import('@/page/Home.vue'),
          meta: { title: '首页' }
        },
        {
          path:'/user',
          component: () => import('@/page/users/index.vue'),
          meta:{ title: '用户管理' },
          redirect:'/user/user-list',
          children:[
            {
              path:'user-list',
              component: () => import('@/page/users/user-list.vue'),
              meta: { title: '用户列表' },
            }
          ]
        },
        {
          path: '/park',
          component: () => import('@/page/park/index.vue'),
          meta: { title: '基础配置' },
          redirect: '/park/park-list',  // 该配置是若点击选择一级菜单时，默认选中并跳转到该一级菜单下的第一个二级菜单
          children:[
            {
              path: 'park-list',
              component: () => import('@/page/park/park-list.vue'),
              meta: { title: '车场管理' },
            },
          ]
        },
        {
          path: '/car',
          component: () => import('@/page/car/index.vue'),
          meta: { title: '场库管理' },
          redirect: '/car/park-record',  // 该配置是若点击选择一级菜单时，默认选中并跳转到该一级菜单下的第一个二级菜单
          children:[
            {
              path: 'park-record',
              component: () => import('@/page/car/park-record.vue'),
              meta: { title: '临停订单' },

            },
            {
              path: 'white-list',
              component: () => import('@/page/car/white-list.vue'),
              meta: { title: '白名单管理' },
            },
            {
              path: 'black-list',
              component: () => import('@/page/car/black-list.vue'),
              meta: { title: '黑名单管理' },
            },
            {
              path: 'monthly-list',
              component: () => import('@/page/car/monthly-list.vue'),
              meta: { title: '月租管理' },
            },
          ]
        },
        {
          path: '/permission',  // 权限页面
          component: () => import('@/page/Permission.vue'),
          meta: {
            title: '权限测试',
            permission: true
          }
        },
        {
          path: '/404',
          component: () => import('@/page/404.vue'),
          meta: { title: '404' }
        },
        {
          path: '/403',
          component: () => import('@/page/403.vue'),
          meta: { title: '403' }
        },
      ]
    },
    {
      path: '/Login',  // 登录页面
      component: () => import('@/page/Login.vue'),
      meta: { title: '登录' }
    },
    {
      path: '*',
      redirect: '/404'
    }
  ]
});